package cn.com.sueframe.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
 * 用来设置响应字符集编码
 * @author anmin
 * Create 2013-4-1
 */
public class CharactorFilter implements Filter {
	//用来存储字符集编码
    private String charactor = "gbk";
	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		res.setContentType("text/html;charset=" + charactor);
		req.setCharacterEncoding(charactor);
		res.setCharacterEncoding(charactor);
		chain.doFilter(req, res);

	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		// TODO Auto-generated method stub
		charactor = config.getInitParameter("charactor");
	}

}
